package com.hiultra.archive.controller;

import com.hiultra.archive.domain.ArcAppraisal;
import com.hiultra.archive.service.IArcAppraisalService;
import com.hiultra.common.annotation.Log;
import com.hiultra.common.core.controller.BaseController;
import com.hiultra.common.core.domain.AjaxResult;
import com.hiultra.common.core.page.TableDataInfo;
import com.hiultra.common.enums.BusinessType;
import com.hiultra.common.utils.bean.BeanValidators;
import com.hiultra.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Validator;
import java.util.List;

/**
 * 鉴定单Controller
 *
 * @author ls
 * @date 2023-08-31
 */
@Api(tags = "鉴定Controller")
@RestController
@RequestMapping("/archive/appraisal")
public class ArcAppraisalController extends BaseController {
    @Autowired
    private IArcAppraisalService arcAppraisalService;
    @Autowired
    protected Validator validator;
    /**
     * 查询鉴定单列表
     */
    @ApiOperation(value = "查询鉴定单列表", notes = "查询鉴定单列表")
    @PreAuthorize("@ss.hasPermi('archive:appraisal:list')")
    @GetMapping("/list")
    public TableDataInfo list(ArcAppraisal arcAppraisal) {
        startPage();
        List<ArcAppraisal> list = arcAppraisalService.selectArcAppraisalList(arcAppraisal);
        return getDataTable(list);
    }

    /**
     * 导出鉴定单列表
     */
    @ApiOperation(value = "导出鉴定单列表", notes = "导出鉴定单列表")
    @PreAuthorize("@ss.hasPermi('archive:appraisal:export')")
    @Log(title = "鉴定单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ArcAppraisal arcAppraisal) {
        List<ArcAppraisal> list = arcAppraisalService.selectArcAppraisalList(arcAppraisal);
        ExcelUtil<ArcAppraisal> util = new ExcelUtil<ArcAppraisal>(ArcAppraisal.class);
        util.exportExcel(response, list, "鉴定单数据");
    }

    /**
     * 获取鉴定单详细信息
     */
    @ApiOperation(value = "获取鉴定单详细信息", notes = "获取鉴定单详细信息")
    @PreAuthorize("@ss.hasPermi('archive:appraisal:query')")
    @GetMapping(value = "/{appraisalId}")
    public AjaxResult getInfo(@PathVariable("appraisalId") Long appraisalId) {
        System.out.println(arcAppraisalService.selectArcAppraisalByAppraisalId(appraisalId).getAppraisalTime());
        return AjaxResult.success(arcAppraisalService.selectArcAppraisalByAppraisalId(appraisalId));
    }

    /**
     * 新增鉴定单
     */
    @ApiOperation(value = "新增鉴定单", notes = "新增鉴定单")
    @PreAuthorize("@ss.hasPermi('archive:appraisal:add')")
    @Log(title = "鉴定单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ArcAppraisal arcAppraisal) {
        arcAppraisal.setCreateBy(getUsername());
        return toAjax(arcAppraisalService.insertArcAppraisal(arcAppraisal));
    }

    /**
     * 修改鉴定单
     */
    @ApiOperation(value = "修改鉴定单", notes = "修改鉴定单")
    @PreAuthorize("@ss.hasPermi('archive:appraisal:edit')")
    @Log(title = "鉴定单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ArcAppraisal arcAppraisal) {
        arcAppraisal.setUpdateBy(getUsername());
        return toAjax(arcAppraisalService.updateArcAppraisal(arcAppraisal));
    }

    /**
     * 删除鉴定单
     */
    @ApiOperation(value = "删除鉴定单", notes = "删除鉴定单")
    @PreAuthorize("@ss.hasPermi('archive:appraisal:remove')")
    @Log(title = "鉴定单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{appraisalIds}")
    public AjaxResult remove(@PathVariable Long[] appraisalIds) {
        return toAjax(arcAppraisalService.deleteArcAppraisalByAppraisalIds(appraisalIds));
    }
}
